package simulator;

import java.math.BigInteger;

class fetch{

}

class decode{
	
	
}

class Execute{
	void UpdateMAR(int addr){
		Register.MAR = change_to_Binary(addr).toCharArray();
	}
	
	void UpdateMAR(char[] addr){
		Register.MAR = addr;
	}
	
	void UpdateMBR(char [] var){
		Register.MBR = var;
	}
	
	void UpdateMBR(Memory memory){
		Register.MBR = memory.MBR;
	}
	
	void SetMemoryMAR(Memory memory){
		memory.SetMAR(Register.MAR);
	}
	
	void SetMemoryMBR(Memory memory){
		memory.SetMBR(Register.MBR);
	}
	
	void ReadMemory(Memory memory){
		SetMemoryMAR(memory);
		memory.read();
		UpdateMBR(memory);
	}

	void WriteMemory(Memory memory){
		SetMemoryMAR(memory);
		SetMemoryMBR(memory);
		memory.write();
	}
	
	char[] ContentPlusOne(char[] var){
		char[] temp = change_to_Binary(change_to_decimal(String.valueOf(var))+1).toCharArray();
		return temp;
	}
	
	char[] ContentMinusOne(char[] var){
		char[] temp = change_to_Binary(change_to_decimal(String.valueOf(Register.MBR))-1).toCharArray();
		return temp;
	}
	
	char[] AddTwoContent(char[] var1,char[] var2){
		int x = change_to_decimal(String.valueOf(var1));
		int y = change_to_decimal(String.valueOf(var2));
		int z = x + y;
		char[] temp = change_to_Binary(z).toCharArray();
		return temp;
	}
	
	char[] SubTwoContent(char[] var1,char[] var2){
		int x = change_to_decimal(String.valueOf(var1));
		int y = change_to_decimal(String.valueOf(var2));
		int z = x - y;
		char[] temp = change_to_Binary(z).toCharArray();
		return temp;
	}
	
	char[] AddImmed(char[] var1, String var2){
		int x = change_to_decimal(String.valueOf(var1));
		int y = change_to_decimal(var2);
		int z = x + y;
		char[] temp = change_to_Binary(z).toCharArray();
		return temp;
	}
	
	char[] SubImmed(char[] var1, String var2){
		int x = change_to_decimal(String.valueOf(var1));
		int y = change_to_decimal(var2);
		int z = x - y;
		char[] temp = change_to_Binary(z).toCharArray();
		return temp;
	}
	
	String MulTwoContent(char[] var1, char[] var2){
		int x = change_to_decimal(String.valueOf(var1));
		int y = change_to_decimal(String.valueOf(var2));
		int z = x * y;
		String temp = change_to_Binary(z);
		return temp;
	}
	
	int Div_remainder(char[] var1, char[] var2){
		int x = change_to_decimal(String.valueOf(var1));
		int y = change_to_decimal(String.valueOf(var2));
		int z = x % y;
		return z;
	}
	
	int Div_quotient(char[] var1, char[] var2, int reminder){
		int x = change_to_decimal(String.valueOf(var1))-reminder;
		int y = change_to_decimal(String.valueOf(var2));
		int z = x/y;
		return z;
	}
	
	char[] And(char[] var1,char[] var2){
		int x = change_to_decimal(String.valueOf(var1));
		int y = change_to_decimal(String.valueOf(var2));
		int z = x&y;
		char[] temp = change_to_Binary(z).toCharArray();
		return temp;
	}
	
	char[] Or(char[] var1,char[] var2){
		int x = change_to_decimal(String.valueOf(var1));
		int y = change_to_decimal(String.valueOf(var2));
		int z = x|y;
		char[] temp = change_to_Binary(z).toCharArray();
		return temp;
	}
	
	char[] Not(char[] var){
		int x = change_to_decimal(String.valueOf(var));
		int z = ~x;
		char[] temp = change_to_Binary(z).toCharArray();
		return temp;
	}
	
	char[] Shift(char[] var1, int count , int lr , int al){
		if(al==1){
			if(lr == 1){
				int i;
				for (i=0; i< var1.length - count; i++){
					var1[i] = var1[i+count];
				}
				for (;i<var1.length;i++)
				{
					var1[i] = '0';
				}
			}
			else if(lr == 0){
				int i;
				for (i=var1.length-1; i>=count; i--){
					var1[i] = var1[i-count];
				}
				for (;i>=0;i--)
				{
					var1[i] = '0';
				}
			}
		}
		if(al == 0){
			if(lr == 1){
				int i;
				for (i=1; i< var1.length - count; i++){
					var1[i] = var1[i+count];
				}
				for (;i<var1.length;i++)
				{
					var1[i] = '0';
				}
			}
			else if(lr == 0){
				int i;
				for (i=var1.length-1; i>=count; i--){
					var1[i] = var1[i-count];
				}
				for (;i>0;i--)
				{
					var1[i] = var1[0];
				}
			}
		}
		return var1;
	}
	
	char[] Rotate(char[] var1, int count , int lr , int al){
		
		int alflag = 0;
		if(al == 1){ alflag = 0;}
		else if(al == 0){alflag =1;}
		
		if(lr == 1){
			char temp;
			int j;
			for (int i = 0; i < count ; i ++){
				temp = var1[alflag];
				for(j = alflag; j < var1.length-1; j++){
					var1[j] = var1[j+1];
				}
				var1[j] = temp;					
			}
		}
			
		else if(lr == 0){
			char temp;
			int j;
			for (int i = 0; i < count; i ++){
				temp = var1[var1.length-1];
				for(j = var1.length-1; j > alflag; j --){
					var1[j] = var1[j-1];
				}
				var1[j] = temp;
			}
		}
		return var1;
	}
	int change_to_decimal(String Binary){
		BigInteger Temp = new BigInteger(Binary,2);	
		return Integer.parseInt(Temp.toString());
	}
	
	
	
	String change_to_Binary(int var){
		BigInteger Temp = new BigInteger(String.valueOf(var));
		return Temp.toString(2);
		
	}
	
	void CalEA(String IR, Memory memory){
		int addr =0;		
		addr = change_to_decimal(IR.substring(10));
		UpdateMAR(addr);
		if(IR.substring(7, 8)=="1"){
			addr = change_to_decimal(String.valueOf(Register.X0))+addr;
			UpdateMAR(addr);
			if(IR.substring(6, 7)=="1"){
				ReadMemory(memory);
				addr = change_to_decimal(String.valueOf(Register.MBR));
				UpdateMAR(addr);
			}
		}
	}
	
	public boolean OP_HALT(String IR)//HALT operation
	{
		return true;
	}
	
	/*OP_LD:	Load operation RegType: 
	 * 1-Load Register From Memory 
	 * 2-Load Index Register from Memory
	 * 3-Load Register with Address
	 * */
	public String OP_Load(String IR, Memory memory, int RegType ){
		try{
			CalEA(IR,memory);		//Refresh MAR
			if (RegType==1){		//Load Register From Memory 
				ReadMemory(memory);
				switch(IR.substring(8, 10)){
				case "00": Register.R0 = Register.MBR;
				case "01": Register.R1 = Register.MBR;
				case "10": Register.R2 = Register.MBR;
				case "11": Register.R2 = Register.MBR;
			}
			}
			else if(RegType==2){	//Load Index Register from Memory
				ReadMemory(memory);
				Register.X0 = Register.MBR;
			}
			else if(RegType==3){	//Load Register with Address
				switch(IR.substring(8, 10)){
				case "00": Register.R0 = Register.MAR;
				case "01": Register.R1 = Register.MAR;
				case "10": Register.R2 = Register.MAR;
				case "11": Register.R2 = Register.MAR;
				}
			}
			return "0011";
		}
		catch(Exception ex){
			return "0000";
		}
	}
	
	/*OP_ST:	Store operation RegType:
	 * 1:Store Register to Memory
	 * 2:Store Index Register to Memory
	 * */
	public String OP_Store(String IR, Memory memory, int RegType){
		try{
			CalEA(IR,memory); //Refresh MAR
			if(RegType == 1){		//Store Register to Memory
				switch(IR.substring(8, 10)){
				case "00":	memory.MBR = Register.R0;
				case "01":	memory.MBR = Register.R1;
				case "10":	memory.MBR = Register.R2;
				case "11":	memory.MBR = Register.R3;
				}
				WriteMemory(memory);
			}
			
			else if (RegType == 2){	//Store Index Register to Memory
				memory.MBR = Register.X0;
				WriteMemory(memory);
			}
			
			return 	"0011";
		}
		catch(Exception ex){
			return	"0000";
		}
	}

	/*OP_JP:	Jump operation JumpType:
 * 1:Jump if Zero
 * 2:Jump if not Equal
 * 3:Jump if Condition Code
 * 4:Unconditional Jump To Address
 * 5:Jump and Save Return Address
 * */
	public String OP_Jump(String IR, Memory memory, int JumpType){
		try{
			CalEA(IR,memory);	//refresh MAR
			
			if(JumpType == 1){	//Jump if Zero
				char[] judge=null;
				switch(IR.substring(8, 10)){
				case "00":	judge = Register.R0;
				case "01":	judge = Register.R1;
				case "10":	judge = Register.R2;
				case "11":	judge = Register.R3;
				}
				
				if(change_to_decimal(String.valueOf(judge))==0){
					Register.PC = Register.MAR;
				}
				else{			
					Register.PC = ContentPlusOne(Register.PC);
				}
			}
			
			else if(JumpType == 2){	//Jump if not Equal
				char[] judge=null;
				switch(IR.substring(8, 10)){
				case "00":	judge = Register.R0;
				case "01":	judge = Register.R1;
				case "10":	judge = Register.R2;
				case "11":	judge = Register.R3;
				}
				if(change_to_decimal(String.valueOf(judge))!=0){
					Register.PC = Register.MAR;
				}
				else{			
					Register.PC = ContentPlusOne(Register.PC);
				}
			}
			
			else if(JumpType == 3){	//Jump if Condition Code
				if(change_to_decimal(String.valueOf(Register.CC))==1){
					Register.PC = Register.MAR;
				}
				else{			
					Register.PC = ContentPlusOne(Register.PC);
				}
			}
			
			else if(JumpType == 4){	//Unconditional Jump To Address
				Register.PC = Register.MAR;
			}
			
			else if(JumpType == 5){	//Jump and Save Return Address
				Register.R3 = ContentPlusOne(Register.PC);
				Register.PC = Register.MAR;
			}
			
			return "0011";
		}
		catch(Exception ex){
			return "0000";
		}
	}

	/*OP_RFS:	RFS Immed Return From Subroutine W/ return code in Immed Portion(optional) stored in R0
 * */
	public String OP_RFS(String IR, Memory memory){
		try{
			Register.R0 = IR.substring(10).toCharArray();
			Register.PC = Register.R3;
			return "0111";
		}
		catch(Exception ex){
			return "0000";
		}
	}
	
	/*OP_SOB:	SOB Subtract One And Branch
 * */
	public String OP_SOB(String IR, Memory memory){
		try{
			char[] judge=null;
			switch(IR.substring(8, 10)){
			case "00":	judge=Register.R0 = ContentMinusOne(Register.R0);
			case "01":	judge=Register.R1 = ContentMinusOne(Register.R1);
			case "10":	judge=Register.R2 = ContentMinusOne(Register.R2);
			case "11":	judge=Register.R3 = ContentMinusOne(Register.R3);
			}
			
			if(change_to_decimal(String.valueOf(judge))>0){	//If c(r) > 0
				CalEA(IR,memory);	//get EA
				Register.PC = Register.MAR;
			}
			else{
				Register.PC = ContentPlusOne(Register.PC);
			}
			
			return "0111";
		}
		catch(Exception ex){
			return "0000";
		}
	}
	
	/*OP_ADD:	Add Memory To Register
	 * */
	public String OP_ADD(String IR, Memory memory){
		try{
			CalEA(IR,memory);
			ReadMemory(memory);
			switch(IR.substring(8, 10)){
			case "00": Register.R0 = AddTwoContent(Register.R0,Register.MBR);
			case "01": Register.R1 = AddTwoContent(Register.R1,Register.MBR);
			case "10": Register.R2 = AddTwoContent(Register.R2,Register.MBR);
			case "11": Register.R3 = AddTwoContent(Register.R3,Register.MBR);
			}			
			return"0011";
		}
		catch(Exception Ex){
			return"0000";
		}
	}

	/*OP_SUB:	Subtract Memory From Register
	 * */
	public String OP_SUB(String IR,	Memory memory){
		try{
			CalEA(IR,memory);
			ReadMemory(memory);
			switch(IR.substring(8, 10)){
			case "00": Register.R0 = SubTwoContent(Register.R0,Register.MBR);
			case "01": Register.R1 = SubTwoContent(Register.R1,Register.MBR);
			case "10": Register.R2 = SubTwoContent(Register.R2,Register.MBR);
			case "11": Register.R3 = SubTwoContent(Register.R3,Register.MBR);
			}		
			return "0011";
		}
		catch(Exception ex){
			
			return "0000";
		}
	}

	/*OP_AIR:	AddImmediate To Register
	 * */
	public String OP_AIR(String IR){
		try{
			switch(IR.substring(8, 10)){
			case "00": Register.R0 = AddImmed(Register.R0,IR.substring(10));
			case "01": Register.R1 = AddImmed(Register.R1,IR.substring(10));
			case "10": Register.R2 = AddImmed(Register.R2,IR.substring(10));
			case "11": Register.R3 = AddImmed(Register.R3,IR.substring(10));
			}	
			return "0011";
		}
		catch(Exception ex){
			return "0000";
		}
	}

	/*OP_SIR:	Subtract Immediate from Register
	 * */
	public String OP_SIR(String IR){
		try{
			switch(IR.substring(8, 10)){
			case "00": Register.R0 = SubImmed(Register.R0,IR.substring(10));
			case "01": Register.R1 = SubImmed(Register.R1,IR.substring(10));
			case "10": Register.R2 = SubImmed(Register.R2,IR.substring(10));
			case "11": Register.R3 = SubImmed(Register.R3,IR.substring(10));
			}	
			return "0011";
		}
		catch(Exception ex){
			return "0000";
		}
	}

	/*OP_MUL:	Multiply Register by Register*/
	public String OP_MUL(String IR){
		try{
			if(IR.substring(6, 8)=="00"){
				String temp = MulTwoContent(Register.R0,Register.R2);
				if(temp.length()>16){
					Register.R0 = temp.substring(0, 16).toCharArray();
					Register.R1 = temp.substring(16).toCharArray();
				}
				else {
					Register.R0 = temp.toCharArray();
				}
			}
			
			if(IR.substring(6, 8)=="10"){
				String temp = MulTwoContent(Register.R2,Register.R0);
				if(temp.length()>16){
					Register.R2 = temp.substring(0, 16).toCharArray();
					Register.R3 = temp.substring(16).toCharArray();
				}
				else {
					Register.R2 = temp.toCharArray();
				}
			}

			return "0011";
		}
		catch(Exception ex){
			return	"0000";
		}
	}

	/*OP_DIV:	Divide Register by Register*/
	public String OP_DIV(String IR){
		try{
			if(IR.substring(6, 8)=="00"){
				int remainder = Div_remainder(Register.R0,Register.R2);
				int quotient = Div_quotient(Register.R0,Register.R2,remainder);
				Register.R0 = change_to_Binary(quotient).toCharArray();
				Register.R1 = change_to_Binary(remainder).toCharArray();
			}
			if(IR.substring(6, 8)=="10"){
				int remainder = Div_remainder(Register.R2,Register.R0);
				int quotient = Div_quotient(Register.R2,Register.R0,remainder);
				Register.R2 = change_to_Binary(quotient).toCharArray();
				Register.R3 = change_to_Binary(remainder).toCharArray();
			}
			return "0011";
		}
		catch(Exception ex){
			return "0000";
		}
	}

	/*OP_TST:	Test the Equality of Register and Register*/
	public String OP_TST(String IR){
		try{
			char[] i = null;
			char[] j = null;
			switch(IR.substring(6, 8)){
			case "00": i = Register.R0;
			case "01": i = Register.R1;
			case "10": i = Register.R2;
			case "11": i = Register.R3;
			}
			switch(IR.substring(8, 10)){
			case "00": j = Register.R0;
			case "01": j = Register.R1;
			case "10": j = Register.R2;
			case "11": j = Register.R3;
			}
			int x = change_to_decimal(String.valueOf(i));
			int y = change_to_decimal(String.valueOf(j));
			if(x==y){
				Register.CC = "0001".toCharArray();
			}
			else{
				Register.CC = "0000".toCharArray();
			}
			return "0011";
		}
		catch(Exception ex){
			return "0000";
		}
	}

	/*OP_AND:	Logical And of Register and Register*/
	public String OP_AND(String IR){
		try{
			char[] j = null;
			switch(IR.substring(8, 10)){
			case "00": j = Register.R0;
			case "01": j = Register.R1;
			case "10": j = Register.R2;
			case "11": j = Register.R3;
			}
			switch(IR.substring(6, 8)){
			case "00": Register.R0 = And(Register.R0,j);
			case "01": Register.R1 = And(Register.R1,j);
			case "10": Register.R2 = And(Register.R2,j);
			case "11": Register.R3 = And(Register.R3,j);
			}
			
			return "0011";
		}
		catch(Exception ex){
			return "0000";
		}
	}
	
	/*OP_OR:	Logical Or of Register and Register*/
	public String OP_OR(String IR){
		try{
			char[] j = null;
			switch(IR.substring(8, 10)){
			case "00": j = Register.R0;
			case "01": j = Register.R1;
			case "10": j = Register.R2;
			case "11": j = Register.R3;
			}
			switch(IR.substring(6, 8)){
			case "00": Register.R0 = Or(Register.R0,j);
			case "01": Register.R1 = Or(Register.R1,j);
			case "10": Register.R2 = Or(Register.R2,j);
			case "11": Register.R3 = Or(Register.R3,j);
			}
			
			return "0011";
		}
		catch(Exception ex){
			return "0000";
		}
	}

	/*OP_NOT:	Logical Not of Register To Register*/
	public String OP_NOT(String IR){
		try{
			switch(IR.substring(6, 8)){
			case "00": Register.R0 = Not(Register.R0);
			case "01": Register.R1 = Not(Register.R1);
			case "10": Register.R2 = Not(Register.R2);
			case "11": Register.R3 = Not(Register.R3);
			}
			
			return "0011";
		}
		catch(Exception ex){
			return "0000";
		}
	}
	
	/*OP_SRC:	Shift Register by Count*/
	public String OP_SRC(String IR){
		try{
			int count = change_to_decimal(IR.substring(12));
			int LRflag = change_to_decimal(IR.substring(6,7));
			int ALflag = change_to_decimal(IR.substring(9,10));
			switch(IR.substring(7, 9)){
			case "00": Register.R0 = Shift(Register.R0,count,LRflag,ALflag);
			case "01": Register.R1 = Shift(Register.R0,count,LRflag,ALflag);
			case "10": Register.R2 = Shift(Register.R0,count,LRflag,ALflag);
			case "11": Register.R3 = Shift(Register.R0,count,LRflag,ALflag);
			}
			return "0011";
		}
		catch(Exception ex){
			return "0000";
		}
	}

	/*OP_RRC:	Rotate Register by Count*/
	public String OP_RRC(String IR){
		try{
			int count = change_to_decimal(IR.substring(12));
			int LRflag = change_to_decimal(IR.substring(6,7));
			int ALflag = change_to_decimal(IR.substring(9,10));
			switch(IR.substring(7, 9)){
			case "00": Register.R0 = Rotate(Register.R0,count,LRflag,ALflag);
			case "01": Register.R1 = Rotate(Register.R0,count,LRflag,ALflag);
			case "10": Register.R2 = Rotate(Register.R0,count,LRflag,ALflag);
			case "11": Register.R3 = Rotate(Register.R0,count,LRflag,ALflag);
			}
			return "0011";
		}
		catch(Exception ex){
			return "0000";
		}
	}
	
	/*OP_IN:	Input Character To Register From Device*/
	public String OP_IN(String IR){
		try{
			char[] fetch = null;
			int DevID = change_to_decimal(IR.substring(11));
			switch(DevID){
			case 0 : fetch = IO.keyValue.toCharArray();
			case 1 : ;
			case 2 : fetch = IO.ReadFile.toCharArray();
			}
			
			switch(IR.substring(7,9)){
				case "00":	Register.R0 = fetch;
				case "01":	Register.R1 = fetch;
				case "10":	Register.R2 = fetch;
				case "11":	Register.R3 = fetch;
				
			}
			return "0011";
		}
		catch(Exception ex){
			return "0000";
			
		}
	}

	/*OP_OUT:	Out character To Device from Register
	*/
	public String OP_OUT(String IR){
		try{
			char[] value = null;
			switch(IR.substring(7,9)){
			case "00":	value = Register.R0;
			case "01":	value = Register.R1;
			case "10":	value = Register.R2;
			case "11":	value = Register.R3;
			}
			
			int DevID = change_to_decimal(IR.substring(11));
			switch(DevID){
			case 0 : ;
			case 1 : IO.Printer = value.toString();
			case 2 : ;
			}
			return "0011";
		}
		catch(Exception ex){
				return "0000";
		}
		
	}

	public String OP_CHK(String IR){
		try{
			switch(IR.substring(7,9)){
			case "00":	Register.R0 = IO.Status.toCharArray();
			case "01":	Register.R1 = IO.Status.toCharArray();
			case "10":	Register.R2 = IO.Status.toCharArray();
			case "11":	Register.R3 = IO.Status.toCharArray();
			
		}
			return "0011";
		}
		catch(Exception ex){
			return "0000";
		}
	}
}
public class Processor {
	
	public static void main(String[] args){
		Memory memory = new Memory();
		Execute execute = new Execute();
		
		Register.MAR=Register.PC.clone(); 			//PC->MAR
		execute.ReadMemory(memory);					//Memory(MAR)->MBR
		Register.IR = Register.MBR.clone();			//MBR->IR
		
		//get operation code

		switch(Register.IR.toString().substring(0, 5)){
		
		case "000000": Register.poweron= execute.OP_HALT(Register.IR.toString()); //HLT
		
		//case "030":	//TRAP r; this will be used in the second part of this project!
			
		case "000001":  Register.MFR = execute.OP_Load(String.valueOf(Register.IR), memory, 1).toCharArray();	//LDR
		case "000002":	Register.MFR = execute.OP_Store(String.valueOf(Register.IR), memory, 1).toCharArray();	//STR
		case "000003":	Register.MFR = execute.OP_Load(String.valueOf(Register.IR), memory, 3).toCharArray();	//LDA
		case "000041":	Register.MFR = execute.OP_Load(String.valueOf(Register.IR), memory, 2).toCharArray();	//LDX
		case "000042":	Register.MFR = execute.OP_Store(String.valueOf(Register.IR), memory, 2).toCharArray();	//STX
		case "000010":	Register.MFR = execute.OP_Jump(String.valueOf(Register.IR), memory, 1).toCharArray();//JZ
		case "000011":	Register.MFR = execute.OP_Jump(String.valueOf(Register.IR), memory, 2).toCharArray();//JNE
		case "000012":	Register.MFR = execute.OP_Jump(String.valueOf(Register.IR), memory, 3).toCharArray();//JCC
		case "000013": 	Register.MFR = execute.OP_Jump(String.valueOf(Register.IR), memory, 4).toCharArray();//JMP
		case "000014": 	Register.MFR = execute.OP_Jump(String.valueOf(Register.IR), memory, 5).toCharArray();//JSR
		case "000015": 	Register.MFR = execute.OP_RFS(String.valueOf(Register.IR), memory).toCharArray();	//RFS
		case "000016": 	Register.MFR = execute.OP_SOB(String.valueOf(Register.IR), memory).toCharArray();	//SOB
		case "000004": 	Register.MFR = execute.OP_ADD(String.valueOf(Register.IR), memory).toCharArray();	//ADD
		case "000005": 	Register.MFR = execute.OP_SUB(String.valueOf(Register.IR), memory).toCharArray();	//SUB
		case "000006": 	Register.MFR = execute.OP_AIR(String.valueOf(Register.IR)).toCharArray();			//AIR
		case "000007": 	Register.MFR = execute.OP_SIR(String.valueOf(Register.IR)).toCharArray();			//SIR
		case "000020": 	Register.MFR = execute.OP_MUL(String.valueOf(Register.IR)).toCharArray();//MUL
		case "000021": 	Register.MFR = execute.OP_DIV(String.valueOf(Register.IR)).toCharArray();//DIV
		case "000022": 	Register.MFR = execute.OP_TST(String.valueOf(Register.IR)).toCharArray();//TST
		case "000023": 	Register.MFR = execute.OP_AND(String.valueOf(Register.IR)).toCharArray();//AND
		case "000024": 	Register.MFR = execute.OP_OR(String.valueOf(Register.IR)).toCharArray();//OR
		case "000025": 	Register.MFR = execute.OP_NOT(String.valueOf(Register.IR)).toCharArray();//NOT
		case "000031": 	Register.MFR = execute.OP_SRC(String.valueOf(Register.IR)).toCharArray();//SRC
		case "000032": 	Register.MFR = execute.OP_RRC(String.valueOf(Register.IR)).toCharArray();//RRC
		case "000061": 	Register.MFR = execute.OP_IN(String.valueOf(Register.IR)).toCharArray();//IN
		case "000062": 	Register.MFR = execute.OP_OUT(String.valueOf(Register.IR)).toCharArray();//OUT
		case "000063": 	Register.MFR = execute.OP_CHK(String.valueOf(Register.IR)).toCharArray();//CHK
		case "000033": //FADD
		case "000034": //FSUB
		case "000035": //VADD
		case "000036": //VSUB
		case "000037": //CNVRTF
		default: Register.MFR = "0011".toCharArray();
		}
	}

}
